package com.fs.generator.ui.jdbc.dialect;

public class MysqlMetadataDialectImpl implements MetadataDialect {

	private String database;

	public static final String TABLES_SQL_TPL = "select table_name, table_comment from information_schema.tables where table_schema='%s' order by table_name;";
	public static final String COL_SQL_TPL = "select COLUMN_NAME as name, COLUMN_COMMENT AS comments, IS_NULLABLE AS nullable\nfrom information_schema.COLUMNS where table_name='%s' and table_schema='%s';";

	public MysqlMetadataDialectImpl(String dbUrl) {
		database = dbUrl.substring(dbUrl.lastIndexOf("/") + 1, dbUrl.indexOf("?"));
	}

	@Override
	public String tablesSql() {
		return String.format(TABLES_SQL_TPL, database);
	}

	@Override
	public String colSql(String tableName) {
		return String.format(COL_SQL_TPL, tableName, database);
	}

	@Override
	public String getDataBase() {
		return database;
	}

}
